
window.onload = function () {
    setLoginInfo();
    findByItem(1);
}

function findByItem(pageNo) {
  axios.get("/goods/findByItem",{
      params: {
          pageNo,
          name:$("goodsName").value
      }
  }).then(resp=>{
      var info = resp.data;
      var str="";
      info.list.forEach(n=>{
          str+=`<div style="width: 200px;height: 300px">
<img src='/img/${n.imgPath}' width="100" height="100" alt=""><br>
          商品名：${n.goodsName}<br>
          单价；${n.money}<br>
          评论：${n.assessNum}<br>
          <input type="button" value="查看" onclick="location.href='/assess.html?id=${n.id}'">
</div>`;
      });
      $("goodsDiv").innerHTML=str;
      var custr ="";
      for (var i=1;i<=info.totalPage;i++){
          custr+=`<a href="javascript:findByItem(${i})" style="margin-left: 10px">${i}</a>`;
      }
      $("cutDiv").innerHTML=custr;
  })
}

function setLoginInfo() {
    axios.get("/users/getLoginUser").then(resp=>{
        var info = resp.data;
        if(info == ''){
            $("loginDiv").innerHTML = "对不起，请先<a href='/login.html'>登陆</a>";
        }
        else{
            $("loginDiv").innerHTML = "欢迎光临，"+info.userName;
        }
    });
}